/**
 * representation of Wildschweinjaeger
 * @author Lukas Koell
 * @author Johannes Riedmann
 * @author David Medenjak
 */

public class WildschweinJaeger extends Erzeuger {

    /** number of runs the Wildschweinjaeger has to accomplish */
    private int runs;
    private boolean beenInterrupted;

    public WildschweinJaeger(String name, Lager outputStorage, int runs) {
        super(name, outputStorage, 1);
        this.runs = runs;
        this.outAmount = 1;
        beenInterrupted = false;
    }

    /**
     * @return number of runs
     */
    public int getRuns() {
        return runs;
    }

    @Override
    public void run() {
        for (int i = 0; i < runs; i++) {
            if (this.isInterrupted()) {
                terminate();
                return;
            }

            // work
            try {
                Thread.sleep(workDuration);
            } catch (InterruptedException e) {
                terminate();
                return;
            }

            // deposit
            depositRessources();
        }
        
        // if wildschweinjaeger has regularly finished his job
        System.out.println("The following Wildschweinjaeger has regularly finished his job:");
        terminate();
        System.out.println();
    }
}
